﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Job.Web.Framework;
using Job.Entity;
using Job.Logic.Company;
using Job.Logic.BaseContent;
using System.Collections.Generic;

namespace Job.Web.Company
{
    public partial class CompanyLogin : BasePage
    {
        private int ErrorCode
        {
            get { return myR["error"].IntValue; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ErrorCode == 1)
                message.InnerHtml = "<font color='#990000'><strong>未登录系统或长时间未操作，请重新登录！</strong></font>";
            else if (ErrorCode == 2)
                message.InnerHtml = "<font color='#990000'><strong>系统内部错误，请重新登录！</strong></font>";
            else
                message.InnerHtml = "<strong>根据相关人才流动法规条例规定，企业在招聘过程中不得以押金、报名费等任何形式收取求职者费用。</strong>";

            //if (!this.IsPostBack)
            //{
            //    BindHunterJob();
            //}
        }


        ////绑定猎头职位列表
        //private void BindHunterJob()
        //{
        //    HunterJobLogic jobLogic = new HunterJobLogic();
        //    DataTable dt = jobLogic.GetTopJob(26);
        //    if (null != dt)
        //    {
        //        int count = dt.Rows.Count;
        //        IList<JobRow> jobs = new List<JobRow>();
        //        int rows = count / 2;
        //        if ((count % 2) > 0) rows++;

        //        for (int i = 0; i < rows; i++)
        //        {
        //            JobRow jobRow = new JobRow();
        //            jobRow.jobNo1 = dt.Rows[i * 2][1].ToString();
        //            jobRow.jobName1 = (string)dt.Rows[i * 2][2].ToString();

        //            if ((i * 2 + 1) < count)
        //            {
        //                jobRow.jobNo2 = (string)dt.Rows[i * 2 + 1][1].ToString();
        //                jobRow.jobName2 = (string)dt.Rows[i * 2 + 1][2].ToString();
        //            }
        //            jobs.Add(jobRow);
        //        }

        //        jobList.DataSource = jobs;
        //        jobList.DataBind();
        //    }
        //}


        //protected void jobList_ItemDataBound(object sender, DataListItemEventArgs e)
        //{
        //    ListItemType type = e.Item.ItemType;
        //    switch (type)
        //    {
        //        case ListItemType.Item:
        //        case ListItemType.AlternatingItem:
        //            {
        //                HyperLink job1 = (HyperLink)e.Item.FindControl("job1");
        //                Label lbJobNo1 = (Label)e.Item.FindControl("jobNo1");
        //                if (job1.Text != null && job1.Text.Length > 0)
        //                {
        //                    job1.NavigateUrl = "../Item.aspx?categoryid="
        //                    + Convert.ToString((int)Constants.CategoryType.Hunter) + "&subjectid="
        //                    + Convert.ToString((int)Job.Web.Framework.Constants.SubjectType.HunterPositionList)
        //                    + "&jobno=" + lbJobNo1.Text.Trim();
        //                }


        //                HyperLink job2 = (HyperLink)e.Item.FindControl("job2");
        //                Label lbJobNo2 = (Label)e.Item.FindControl("jobNo2");
        //                if (job2.Text != null && job2.Text.Length > 0)
        //                {
        //                    job2.NavigateUrl = "../Item.aspx?categoryid="
        //                    + Convert.ToString((int)Job.Web.Framework.Constants.CategoryType.Hunter) + "&subjectid="
        //                    + Convert.ToString((int)Constants.SubjectType.HunterPositionList)
        //                    + "&jobno=" + lbJobNo2.Text.Trim();
        //                }
        //                break;
        //            }

        //    }
        //}

        protected void ibtLogin_Click(object sender, ImageClickEventArgs e)
        {
            CompanyLogic logic = new CompanyLogic();
            JobCompanyInfo company = logic.GetCompanyByLogin(tbLogin.Text.Trim());
            if (null == company)
            {
                message.InnerHtml = "<font color='#990000'><strong>登录帐号不存在！</strong></font>";
                return;
            }

            if (company.LoginPswd.Equals(tbPassword.Text))
            {
                SessionCompany sCompany = new SessionCompany();
                sCompany.CompanyId = company.CompanyInfoId;
                sCompany.CompanyName = company.CompanyName;

                MySession session = new MySession();
                session.AddCompany2Session(sCompany);

                Response.Redirect("CompanyManager.aspx?categoryid=2&subjectid=2");
                return;
            }
            else
            {
                message.InnerHtml = "<font color='#990000'><strong>用户名或密码错误！</strong></font>";
            }
        }

    }
}
